package com.support.config;

import com.support.build.RateLimitMethodInterceptor;
import com.support.build.RateLimiterAdvisor;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Role;

/**
 * @author youshang
 * @date 2020/12/17 19:11
 **/
@Configuration(proxyBeanMethods = false)
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public class RateLimiterConfiguration {

    @Bean
    @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
    public RateLimiterAdvisor registerRateLimiterAdvisor(RateLimitMethodInterceptor registerMethodInterceptor) {
        RateLimiterAdvisor rateLimiterAdvisor = new RateLimiterAdvisor(registerMethodInterceptor);
        return rateLimiterAdvisor;

    }


    @Bean
    @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
    public RateLimitMethodInterceptor registerMethodInterceptor() {
        RateLimitMethodInterceptor rateLimitMethodInterceptor = new RateLimitMethodInterceptor();
        return rateLimitMethodInterceptor;
    }

}
